package sdp;

/** Simple class wrapping a ball's position, size and velocity. */
public class BallState {
	/// Construct with given starting position and size.
	public BallState( Vector2 position, double radius ) {
		assert radius > 0;
		assert position != null;
		
		this.radius = radius;
		reset( position );
	}
	
	/// Get the radius of the ball.
	public double getRadius() {
		return radius;
	}
	
	/// Get the ball's position.
	public Vector2 getPosition() {
		return position;
	}
	
	/// Get the ball's velocity.
	public Vector2 getVelocity() {
		return velocity;
	}
	
	/// Update the ball's position and velocity (based on the time elapsed since the last update).
	public void update( Vector2 newPosition, double timeStep ) {
		assert timeStep > 0.0;
		assert newPosition != null;
		
		velocity = newPosition.minus( position ).times( 1.0 / timeStep );
		position = newPosition;
	}
	
	/// Reset the ball's position with zero velocity.
	public void reset( Vector2 newPosition ) {
		assert newPosition != null;
		
		position = newPosition;
		velocity = new Vector2( 0.0, 0.0 );
	}
	
	private Vector2 position;
	private Vector2 velocity;
	private double  radius;
}
